__author__ = 'aesop'
#coding:utf-8

from bson import ObjectId
import get_mongo_con
import time

__read_journal_collection = get_mongo_con.get_collection("read_journal")
def new_alive_journal(stu_id, note_id):
    now_time = time.time()

    return __read_journal_collection.update({"note_id":ObjectId(note_id)},{"$push":{str(stu_id) + ".time":now_time}})

def new_pointer_journal(note_id, stu_id, pointer_pos, user_agent):
    single_element = {
        "pointer_position":pointer_pos,
        "user_agent":user_agent
    }
    return __read_journal_collection.update({"note_id":ObjectId(note_id)},{"$push":{str(stu_id) + ".pointer":single_element}})

def get_journal_by_note_id(note_id):
    return __read_journal_collection.find_one({"note_id",ObjectId(note_id)})


def new_journal_index(note_id):
    return __read_journal_collection.insert({"note_id":note_id})